package com.wd.db;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author long
 * @date 2013-5-2 ����1:33:49
 * @qq 108232706
 * @description DBMgr
 */
public class DBMgr {

	public final int index;// ��ţ���Ӧ�̳߳ص�����
	// public static final Properties dbProps= new Properties();
	private Connection connection;

	public Connection Open() {
		return connection;
	}

	public DBMgr(int _index) throws Throwable {
		this.index = _index;
		/*
		 * Properties p = new Properties(); p.setProperty("driverClassName",
		 * "com.mysql.jdbc.Driver"); p.setProperty( "url",
		 * "jdbc:mysql://192.168.0.144:3306/Mutil_TexasPoker?useUnicode=true&amp;characterEncoding=GBK"
		 * ); p.setProperty("password", "1234"); p.setProperty("username",
		 * "long"); p.setProperty("maxActive", "120"); p.setProperty("maxIdle",
		 * "50"); p.setProperty("minIdle", "30"); p.setProperty("initialSize",
		 * "30"); // We want this for failover on the slaves
		 * p.put("autoReconnect", "true"); // We want to load balance between
		 * the slaves p.put("roundRobinLoadBalance", "true");
		 */
		initDataBases();
	}

	/**
	 * ��ʼ��������ݿ�����
	 * 
	 * @throws Throwable
	 */
	private void initDataBases() throws Throwable {
		connection=initConnectionByName();
	}

	private Connection initConnectionByName() throws Throwable {

		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			throw new Throwable("��ʼ����ݿ����ӳش���" + e);
		}
		try {
			// ���ó�ʱ
			// DriverManager.setLoginTimeout(30);
			return DriverManager
					.getConnection(
							"jdbc:mysql://192.168.0.144:3306/Mutil_TexasPoker?useUnicode=true&amp;characterEncoding=GBK",
							"long", "1234");
		} catch (Exception e) {
			throw e;
		} finally {

		}

	}
}
